<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item, index) in tabbarList"
				:class="[item.centerItem ? 'center-item' : item.classType]"
				:style="{width:tabbarList.length==4 ?'25%':'20%'}" @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
					
					<!-- <image src="../../../../static/img/notice.png"></image> -->
				</view>
				<view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
					<text>{{ item.text }}</text>
				</view>
			</view>
		</block>
		<uni-popup class="homePage-bottom-popup" ref="popup" background-color="none" @change="change">
			<view class="tabbar-box-wrap">
				<view class="tabbar-box">
					<view class="tabbar-box-item" @click="goToPage('/pages/myManage/schoolSquare/publishSchool')">
						<image class="box-image" src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/img2023/img/grid-3.png" mode="aspectFit"></image>
						<text class="explain">发布校园圈</text>
					</view>
					<view class="tabbar-box-item" @click="goToPage('/pages/bbb/bbbPublish')">
						<image class="box-image" src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/img2023/img/grid-7.png" mode="aspectFit"></image>
						<text class="explain">发布帮帮吧</text>
					</view>
					<view class="tabbar-box-item" @click="goToPage('/pages/idleSquare/publishIdle')">
						<image class="box-image" src="https://cmtq-1317574530.cos.ap-guangzhou.myqcloud.com/img2023/img/xianzhi3.png" mode="aspectFit"></image>
						<text class="explain">发布闲置</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				currentItem: 0,
				addVisible: false,
				tabbarList: [{
					id: 0,
					path: '/pages/index/index',
					icon: '/static/icon/home_light.png',
					selectIcon: '/static/icon/home_fill_light.png',
					text: '首页',
					classType: 'tabbar-home-item',
					centerItem: false
				}, {
					id: 1,
					path: '/pages/bbb/list',
					icon: '/static/icon/search.png',
					selectIcon: '/static/icon/search-fill.png',
					text: '帮帮吧',
					classType: 'tabbar-monitor-item',
					centerItem: false
				}, {
					id: 2,
					path: '/pages/add/add',
					icon: '/static/icon/add1.png',
					selectIcon: '/static/icon/add1.png',
					text: '',
					classType: 'tabbar-center-item',
					centerItem: false
				}, {
					id: 3,
					path: '/pages/chat/notice/notices',
					icon: '/static/icon/message_light.png',
					selectIcon: '/static/icon/message_fill_light.png',
					text: '消息',
					classType: 'tabbar-monitor-item',
					centerItem: false
				}, {
					id: 4,
					path: '/pages/my/my',
					icon: '/static/icon/my_light.png',
					selectIcon: '/static/icon/my_fill_light.png',
					text: '我的',
					classType: 'tabbar-me-item',
					centerItem: false
				}, ]
			}
		},
		mounted() {
			this.currentItem = this.currentPage;
			uni.hideTabBar();

		},
		methods: {
			goToPage(url){
				console.log(url)
				if (!url) return;
				uni.navigateTo({
					url
				});
			},
			changeItem(item) {
				let _this = this;

				//_this.currentItem = item.id;

				if (item.id === 2) {

					//todo 跳转到自己需要的界面
					// uni.navigateTo({
					// 	url: '../../pages/addEquipment/addEquipment'
					// })
					this.$refs.popup.open('bottom')
					return
				}
				this.$refs.popup.close('bottom')
				uni.switchTab({
					url: item.path
				});
			},
			change(e) {
				// console.log('popup- c', e)
			},
			newBuildProject() {

				this.$refs.popup.close()
				//todo 跳转到自己需要的界面
				// uni.navigateTo({
				// 	url: '../../pages/newProject/newProject'
				// })
			},
			addEquipment() {
				this.$refs.popup.close()
				//todo 跳转到自己需要的界面
				// uni.navigateTo({
				// 	url: '../../pages/addEquipment/addEquipment'
				// })
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

.tabbar-box-wrap {
	//position: absolute;
	width: 100%;
	padding: 50rpx;
	box-sizing: border-box;
	margin-bottom:80rpx;
	//bottom: 30rpx;
	//left: 0;
	.tabbar-box {
		position: relative;
		display: flex;
		width: 100%;
		background: #fff;
		border-radius: 20upx;
		padding: 15upx 20upx;
		box-sizing: border-box;
		z-index: 2;
		box-shadow: 0px 2px 5px 2px rgba(0, 0, 0, 0.1);
		&:after {
			content: '';
			position: absolute;
			bottom: -16upx;
			left: 0;
			right: 0;
			margin: auto;
			width: 50upx;
			height: 50upx;
			transform: rotate(45deg);
			background: #fff;
			z-index: 1;
			box-shadow: 2px 2px 5px 1px rgba(0, 0, 0, 0.1);
			border-radius: 2px;
		}
		&:before {
			content: '';
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background: #ffffff;
			border-radius: 20upx;
			z-index: 2;
		}
		.tabbar-box-item {
			// position: relative;
			width: 100%;
			z-index: 3;
			margin: 10upx;
			color: $uni-color-subtitle;
			text-align: center;
			font-size: $uni-font-size-base;
			.box-image {
				width: 100%;
				height: $uni-img-size-lg;
			}
		}
	}
}
	.tabbar-container {
		z-index:9999;
		position: fixed;
		bottom: 10rpx;
		left: 0;
		width: 95%;
		margin-left:2.5%;
		border-radius: 80rpx;
		//height: 120rpx;
		box-shadow: 0 0 5px #D7D7D7;
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #444444;
		z-index: 10;
		background: #fff;
	}

	.tabbar-container .tabbar-item {
		width: 20%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;

		.item-top image {
			width: 100%;
			height: 100%;
		}
	}

	.tabbar-container .item-active {
		color: #12ae85;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
		// opacity: 0.9;
	}

	// .tabbar-container .tabbar-item .item-top {
	// 	width: 70rpx;
	// 	height: 70rpx;
	// 	padding: 10rpx;
	// }

	.tabbar-container .tabbar-add-item {
		// opacity: 0.5!important;
	}

	.tabbar-container .tabbar-home-item .item-top {
		width: 40rpx;
		height: 40rpx;
	}

	.tabbar-container .tabbar-monitor-item .item-top {
		width: 40rpx;
		height: 40rpx;
	}

	.tabbar-container .tabbar-notice-item .item-top {
		width: 40rpx;
		height: 40rpx;
	}
	.tabbar-container .tabbar-center-item .item-top {
		width: 60rpx;
		height: 60rpx;
	}

	.tabbar-container .tabbar-me-item .item-top {
		width: 40rpx;
		height: 40rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -50rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0 0 5px #D7D7D7;
		background-color: #ffffff;
	}
	.tabbar-container .center-item .item-top {
		width:80%;
		height:80%;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 26rpx;
		line-height:40rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}

	.homePage-bottom {
		// position: fixed;
		// bottom: 0;
		// width: calc(100vw - 40rpx);
		// z-index: 10;
		position: absolute;
		left: 50%;
		bottom: 50rpx;
		transform: translateX(-50%);
		z-index: -1;

		&-popup {
			z-index: -1;

			&-content {
				min-height: 340rpx;
				border-top-left-radius: 50rpx;
				border-top-right-radius: 50rpx;
				background-color: #fff;
				padding: 0 60rpx 70rpx 60rpx;

				.popup-btn {
					margin: 30rpx auto;
					padding-top: 30rpx;

					.popup-btn-left {
						width: 230rpx;
						text-align: center;
					}

					.popup-btn-right {
						width: 230rpx;
						text-align: center;
					}
				}
			}
		}
	}
</style>